﻿<%@ page title="" language="C#" masterpagefile="~/MasterPages/MasterPagePrivate.master" autoeventwireup="true" inherits="Pages_Admin_SendNewsletter, BtcHousing" stylesheettheme="ServerControls" %>

<asp:Content ID="Content1" ContentPlaceHolderID="PageHeader" Runat="Server">
    <script language="javascript" type="text/javascript">        
        function ShowTestPopup() {
            if(Page_ClientValidate('SaveInfo')) {
                var newsLetterID = $('#<%=ddlTitle.ClientID %>').val();
                var url = '/Pages/Admin/NewsletterTest.aspx?<%=AppConstants.QueryString.ID %>=' + newsLetterID + '&Subject=' + escape($('#<%=txtSubject.ClientID %>').val());
                ShowCenteredPopUp(url, 'TestNewsletter', 800, 400, true);
            }
        }
        function SendNewsLetters()
        {
            if(Page_ClientValidate('SaveInfo'))
            {                
                var newsLetterID = $('#<%=ddlTitle.ClientID %>').val();
                if (newsLetterID.length > 0) {
                    ShowModalPopup('divSendingNewsLetter', '', '', true);
                    $('#divSendNewsletterMessage').hide().html('');
                    $('#divSendNewsletterLoading').show();
                    var recipients = GetSelectedRecipients();
                    PageMethods.SendNewsLetters(newsLetterID, $('#<%=txtSubject.ClientID %>').val(), recipients, SendNewsLetters_Success, OnAjax_Error, OnAjax_TimeOut);
                }
            }
        }
        function SendNewsLetters_Success(result) {
            $('#divSendNewsletterMessage').show().html(result);
            $('#divSendNewsletterLoading').hide();
        }
        function GetSelectedRecipients()
        {
            var ids = '';            
            if($('#chkDevelopers').is(':checked'))
                ids = $('#chkDevelopers').val();
            if($('#chkServiceProviders').is(':checked'))
            {
                ids += ids.length > 0 ? ',' : '';
                ids += $('#chkServiceProviders').val();
            }
            if($('#chkIndividuals').is(':checked'))
            {
                ids += ids.length > 0 ? ',' : '';
                ids += $('#chkIndividuals').val();
            }
            if($('#chkNewsletterSubscribers').is(':checked'))
            {
                ids += ids.length > 0 ? ',' : '';
                ids += $('#chkNewsletterSubscribers').val();
            }
            return ids;
        }        
    </script>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="PageBody" Runat="Server">
    <h4 id="h4Heading" runat="server">Send Newsletter</h4>    
    <div id="divMessage" runat="server" visible="false" enableviewstate="false"></div>        
    <div class="clearboth"></div>
    <%--<div>
        <a href="/Pages/Admin/ContentList.aspx">Back to Content List</a>
    </div>--%>
    
    <asp:Panel ID="pnlFormContainer" runat="server">
        <%--Content Information Group Box Start--%>       
        <table cellpadding="3" cellspacing="0" style="width:100%;">
            <colgroup>
                <col style="width:145px;" />
                <col /> 
            </colgroup>
			<tr>
				<td>Title<span class="requiredMark">*</span></td>
				<td>
					<asp:DropDownList ID="ddlTitle" runat="server" OnSelectedIndexChanged="ddlTitle_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList>
					<asp:RequiredFieldValidator ID="rfvTitle" runat="server"
						ControlToValidate="ddlTitle" SetFocusOnError="true"
						ErrorMessage="Please Select a Newsletter." Display="Dynamic"
						ValidationGroup="SaveInfo">
					</asp:RequiredFieldValidator>
				</td>
			</tr>
            <tr>
                <td>Newsletter Subject</td>
                <td>
                    <asp:TextBox ID="txtSubject" runat="server" MaxLength="500"></asp:TextBox>
					<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
						ControlToValidate="txtSubject" SetFocusOnError="true"
						ErrorMessage="Please Enter a Newsletter Subject." Display="Dynamic"
						ValidationGroup="SaveInfo">
					</asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td>Send To</td>
                <td>
                    <table cellpadding="3" cellspacing="0" style="width:100%;">            
			            <tr>
                            <td><input type="checkbox" id="chkDevelopers" value="<%= ConfigReader.DeveloperUserGroupID %>" /><label for="chkDevelopers">Developers</label></td>
                        </tr>
                        <tr>
                            <td><input type="checkbox" id="chkServiceProviders" value="<%= ConfigReader.ServiceProviderUserGroupID %>" /><label for="chkServiceProviders">Service Providers</label></td>
                        </tr>
                        <tr>
                            <td><input type="checkbox" id="chkIndividuals" value="<%= ConfigReader.IndividualUserGroupID %>" /><label for="chkIndividuals">Individuals</label></td>
                        </tr>
                        <tr>
                            <td><input type="checkbox" id="chkNewsletterSubscribers" value="0" /><label for="chkNewsletterSubscribers">Newsletter Subscribers</label></td>
                        </tr>                        
                    </table>                     
                </td>
            </tr>
            <tr>
				<td colspan="2">
                    <div id="divNewsletterHtml" runat="server" style="border:Green 1px solid; padding:10px;"></div>
				</td>
			</tr>			
        </table>

        <div class="ButtonContainer">
            <input type="button" value="Send" class="ButtonCommon" onclick="SendNewsLetters();" />
            <input type="button" value="Test this Newsletter" class="ButtonInActive" onclick="ShowTestPopup();" />
        </div>
            
        <%--Content Information Group Box End--%>
   </asp:Panel>

<%-- Newsletter Loading Modal Popup Section Start --%>
<div id="divSendingNewsLetter" class="PopupContainer" style="display: none; width:420px; height:auto;">        
    <div class="PopupHeaderMiddle">&nbsp;</div> 
    <div class="PopupBody" style="padding:5px; height:50px;">        
        <div id="divSendNewsletterMessage" style="margin-top:18px; margin-left:10px; display:none; font-weight:bold;"></div>
        <div id="divSendNewsletterLoading" style="margin-top:18px; margin-left:10px; font-weight:bold;" >
            <div class="floatleft">Sending Newsletter... &nbsp;</div>
            <div class="floatleft"><img src="/Images/Loading.gif" alt="" title=""/></div>
            <div class="clearboth"></div>
        </div>
    </div>
    <div class="PopupButtonContainer">
        <input type="button" value="Close" class="ButtonCommon" onclick="HideModalPopup();" />
    </div>
</div>
<%-- Newsletter Loading Modal Popup Section End--%>
</asp:Content>
